home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / misc / edu / globe099src.lha / Ami-Globe / read_org.c < prev    next >
C/C++ Source or Header  |  1994-11-17  |  7KB  |  180 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*      fichier         : read_org.c                                    */
  4. /*      projet          : amiglobe                                      */
  5. /*      date création   : 28/08/94                                      */
  6. /*      commentaire     : lecture du fichier donnees/organisations      */
  7. /*      révision        : $VER: read_org.c 1.008 (10 Sep 1994) */
  8. /*      copyright       : Olivier Collard, Thomas Landspurg             */
  9. /*                                                                      */
  10. /************************************************************************/
  11.  
  12.  
  13. /************************************************************************/
  14. /*      includes                                                        */
  15. /************************************************************************/
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <libraries/mui.h>
  20. #include <proto/muimaster.h>
  21. #include <utility/hooks.h>
  22. #include <clib/alib_protos.h>
  23.  
  24. #include "read_org.h"
  25. #include "amiglobe_interf.h"
  26.  
  27. /************************************************************************/
  28. /*      variables externes                                              */
  29. /************************************************************************/
  30. extern struct  ObjApp  *My_App;
  31.  
  32. /************************************************************************/
  33. /*      variables privées                                               */
  34. /************************************************************************/
  35. FILE * OrganisationFile=NULL;
  36. long int OrganisationPosition[50]; /* position de la description de l'organisation
  37.                              dans le fichier*/
  38. char ** OrganisationList=NULL;
  39. /************************************************************************/
  40. /*      fonctions privées                                               */
  41. /************************************************************************/
  42. void
  43. Show_Organisation_Description(int numero);
  44.  
  45.  
  46. /************************************************************************/
  47. /*      defines                                                         */
  48. /************************************************************************/
  49. #define REG(x) register __ ## x
  50. #define ASM    __asm
  51. #define SAVEDS __saveds
  52.  
  53. /************************************************************************/
  54. /*      hooks                                                           */
  55. /************************************************************************/
  56.  
  57. void SAVEDS ASM cycle_func(void)
  58. {
  59.     ULONG sel;
  60.     get(My_App->CY_organisation,MUIA_Cycle_Active,&sel);
  61.     Show_Organisation_Description(sel);
  62. }
  63.  
  64. struct Hook cycle_hook =
  65. {
  66.         {NULL,NULL},
  67.         (void *)cycle_func,
  68.         NULL,NULL
  69. };
  70.  
  71. /************************************************************************/
  72. /*      implémentation                                                  */
  73. /************************************************************************/
  74.  
  75. /* -------------------------- Create_CY_Organisation ---------------------------
  76.  
  77.  Commentaire:crée le cycle gadget CY_Organisation en fonction de ce qu'il y a
  78.              dans le fichier donnees/organisations
  79.  
  80. */
  81.  
  82. void
  83. Create_CY_organisation(void)
  84. {
  85.     char * buffer=(char *)malloc(8192);
  86.     int i=1;
  87.     OrganisationList=(char **)malloc(50*sizeof(char *));
  88. /*    int j; */
  89.  
  90.     OrganisationFile= fopen ("donnees/organisations","r");
  91.     if (OrganisationFile!=NULL)
  92.     {
  93.         fgets(buffer,8192,OrganisationFile);
  94.         OrganisationList[0]=(char *)malloc(strlen(buffer));
  95.         strncpy(OrganisationList[0],buffer,strlen(buffer)-1);
  96.         OrganisationList[0][strlen(buffer)-1]='\0';
  97.         OrganisationPosition[0]=ftell(OrganisationFile);
  98.         while (buffer[0]!='#')
  99.         {
  100.             while (buffer[0]!='$')
  101.                 fgets(buffer,8192,OrganisationFile);
  102.             fgets(buffer,8192,OrganisationFile);
  103.             if (buffer[0]!='#')
  104.             {
  105.                 OrganisationList[i]=(char *)malloc(strlen(buffer));
  106.                 strncpy(OrganisationList[i],buffer,strlen(buffer)-1);
  107.                 OrganisationList[i][strlen(buffer)-1]='\0';
  108.                 OrganisationPosition[i]=ftell(OrganisationFile);
  109.                 i++;
  110.             }
  111.             else
  112.                 OrganisationList[i]=NULL;
  113.         }
  114. /*        MUI_DisposeObject(My_App->CY_organisation); */
  115.         set(My_App->CY_organisation,MUIA_Cycle_Entries,OrganisationList);
  116.         DoMethod(My_App->CY_organisation,MUIM_Notify,MUIA_Cycle_Active,
  117.                 MUIV_EveryTime, My_App->CY_organisation,2,MUIM_CallHook,&cycle_hook);
  118.     }
  119. /*    for (j=0;j<i;j++)
  120.         free(OrganisationList[j]);*/
  121. /*    free(OrganisationList); */
  122.     free(buffer);
  123.     get(My_App->CY_organisation,MUIA_Cycle_Active,&i);
  124.     Show_Organisation_Description(i);
  125. }
  126.  
  127. /* ----------------------- Show_Organisation_Description -----------------------
  128.  
  129.  Commentaire:crée le floattext correspondant au nom de la description en paramètre
  130.  
  131. */
  132.  
  133. void
  134. Show_Organisation_Description(int numero)
  135. {
  136.     if (OrganisationFile !=NULL)
  137.     {
  138.         char * buffer=(char *)malloc(8192);
  139.         char * texte=(char *)malloc(8192*2);
  140.         texte[0]='\0';
  141.         fseek(OrganisationFile,OrganisationPosition[numero],SEEK_SET);
  142.         fgets(buffer,8192,OrganisationFile);
  143. /*        set(My_App->TX_nombre_adherent,
  144.             MUIA_Text_Contents,buffer);*/
  145.         fgets(buffer,8192,OrganisationFile);
  146.         set(My_App->TX_organisation_officiel,
  147.             MUIA_Text_Contents,buffer);
  148.         fgets(buffer,8192,OrganisationFile);
  149.         while (buffer[0]!='$')
  150.         {
  151.             texte=strcat(texte,buffer);
  152.             fgets(buffer,8192,OrganisationFile);
  153.         }
  154.         set(My_App->LV_organisation,MUIA_Floattext_Justify,TRUE);
  155.         set(My_App->LV_organisation,MUIA_Floattext_Text,texte);
  156.         free(texte);
  157.         free(buffer);
  158.     }
  159. }
  160. /* ---------------------------- Dispose_Organisation ----------------------------
  161.  
  162.  Commentaire:libère la mémoire occupée par la liste des organisations
  163.              clôt le fichier de description
  164. */
  165.  
  166. void
  167. Dispose_Organisation(void)
  168. {
  169.     int i=0;
  170.     if (OrganisationList!=NULL)
  171.     {
  172.         while (OrganisationList[i]!=NULL)
  173.             free(OrganisationList[i++]);
  174.         free(OrganisationList);
  175.     }
  176.     if (OrganisationFile!=NULL)
  177.         fclose(OrganisationFile);
  178. }
  179.  
  180.